package com.jmb.apiplatform.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jmb.apiplatform.common.PageResult;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.mapper.ApiTestAssertLogMapper;
import com.jmb.apiplatform.pojo.*;
import com.jmb.apiplatform.service.ApiTestAssertLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiTestAssertLogServiceImpl implements ApiTestAssertLogService {
    @Autowired
    private ApiTestAssertLogMapper apiTestAssertLogMapper;

    /**
     * 新增断言日志
     * @param apiTestAssertLog 断言日志
     */
    @Override
    public void saveApiTestAssertLog(ApiTestAssertLog apiTestAssertLog) throws ValidException {
        apiTestAssertLogMapper.insertApiTestCaseAssertLog(apiTestAssertLog);
    }

    @Override
    public PageResult<ApiTestAssertLogVO> findApiTestAssertLogList(ApiTestAssertLogTO apiTestAssertLogTO) {
        PageHelper.startPage(apiTestAssertLogTO.getPageNum(), apiTestAssertLogTO.getPageSize());
        List<ApiTestAssertLogVO> apiTestAssertLogVOList = apiTestAssertLogMapper.selectApiTestCaseAssertLogList(apiTestAssertLogTO);
        Page<ApiTestAssertLogVO> p = (Page<ApiTestAssertLogVO>)apiTestAssertLogVOList;

        return new PageResult<>(p.getTotal(), p.getResult());
    }
}
